package com.briup.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.reggie.dto.OrdersDto;
import com.briup.reggie.entity.Orders;
import com.briup.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import com.briup.reggie.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }

    /**
     * 前端历史订单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page> pageFront(int page, int pageSize) {
        Page<OrdersDto> ordersDtoPage = orderService.pageFront(page, pageSize);
        //日志输出看一下
        log.info("ordersDtoPage:{}", ordersDtoPage);
        return R.success(ordersDtoPage);
    }

    /**
     * 订单明细
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page> pageBackend(int page, int pageSize, Long number, String beginTime, String endTime) {
        Page<OrdersDto> ordersDtoPage = orderService.pageBackend(page, pageSize,number,beginTime,endTime);
        //日志输出看一下
        log.info("ordersDtoPage:{}", ordersDtoPage);
        return R.success(ordersDtoPage);
    }

    /**
     * 再来一单
     * @param map
     * @return
     */
    @PostMapping("/again")
    public R<String> again(@RequestBody Map<String,String> map){
        orderService.again(map);
        return R.success("喜欢吃就再来一单吖~");
    }

    /**
     * 修改订单状态
     * 派送
     * @param map
     * @return
     */
    @PutMapping
    public R<String> changeStatus(@RequestBody Map<String, String> map) {
        orderService.changeStatus(map);
        return R.success("订单状态修改成功");
    }
}
